<template>
  <div class="game">
    <div class="timers">
      <div class="tis" v-for="i in core.smlt" :key="i" :class="{ cur: i === core.smlt[core.ostIndex] }">X{{ i }}</div>
    </div>
    <div class="home" :style="style">
      <!-- <Cards v-for="(item, idx) in list" :key="item.id" :col="idx" :timer="timer" :row="row" :offset="item.offset"
        :height="height" :size="size" :types="types" ref="cards"></Cards> -->
      <div v-for="col in core.cols" :key="col.id" class="col" :style="{ width: Config.CARD_WIDTH + 'px' }">
        <div v-for="card in col.cards" class="card" :style="card.style">
          <img class="pic" :src="'./imgs/handmah_' + (Number(card.type) + 11) + '.png'" />
          <!-- <div class="txt">{{ txt }}</div>
            <div class="pid">{{ pid }}</div> -->
            <div class="idx">{{ card.order }}</div>
          <div class="ani" v-if="card.isChoose">
            <Effect></Effect>
          </div>
        </div>
      </div>
    </div>
    <div class="btn" @click="play()">{{ core.running ? '' : '开始'}}</div>
  </div>

</template>

<script>
// import Cards from '../components/cards.vue';
import Card from '../components/card.vue';
import Effect from '../components/effect.vue';

import { sleep, groupArrayBySeven } from "../components/tooler"
// import anime from 'animejs/lib/anime.es.js';
// import conn from './conn';
import { core } from "../components/game/index"
import { Config } from '../components/game/config';
// console.log(core)

const w = 64;
const h = 96;

export default {
  components: { Effect },
  data() {

    return {
      core: core,
      Config: Config,
      style: {
        width: 0,
        height: 0
      }
    }
  },
  computed: {

  },
  created() {
    this.core.init(w * 5, h * 7);
    this.style = {
      width: this.Config.GAME_WIDTH + 'px',
      height: this.Config.GAME_HEIGHT + 'px',
    }
  },
  mounted() {
    // this.start()
  },
  computed: {

  },
  methods: {
    async play(n) {
      core.play()
    },
  },

}
</script>

<style scoped>
.home {
  display: flex;
  overflow-x: hidden;
  overflow-y: auto;
  margin: auto;
}

.timers {
  display: flex;
  justify-content: space-around;
  align-items: center;
  gap: 10px;
}

.tis {
  flex: 1;
  background: #f0f0f0;
  color: #999;
  padding: 4px;
  text-align: center;
}

.btn {
  position: fixed;
  z-index: 1;
  left: 0;
  right: 0;
  margin: auto;
  bottom: 0;
  width: 50px;
  height: 50px;
  background: red;
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  cursor: pointer;
}

.cur {
  background: #ff0000;
  color: #fff;
}

.col {
  position: relative;
}

.card {
  color: #000;
  border: solid 1px #999;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100px;
  height: 100px;
  position: absolute;
  left: 0;
  top: 0;
  font-size: 20px;
}

.pic {
  display: block;
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.ani {
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  opacity: 0.3;
}

.idx {
  position: absolute;
  left: 4px;
  top: 4px;
  font: 12px;
  color: #d40707;
  z-index: 2;
  transform: scale(0.7);
}
</style>
